package cn.wzx.util;

import cn.wzx.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class SessionUtils {

    public static User getUser() {
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication1 = context.getAuthentication();
        User user = (User) authentication1.getPrincipal();
        return user;
    }

    public static String getUid() {
        User user = getUser();
        if (user == null) {
            return "";
        }
        return user.getId();
    }

    public static String getUsername() {
        User user = getUser();
        if (user == null) {
            return "";
        }
        return user.getUsername();
    }
}
